package com.ruoyi.project.wechatprogram.wxtimerlog.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.wxtimerlog.domain.WxTimerLog;
import com.ruoyi.project.wechatprogram.wxtimerlog.service.IWxTimerLogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 定时任务执行记录Controller
 * 
 * @author xinchen
 * @date 2020-05-25
 */
@Controller
@RequestMapping("/wechatprogram/wxtimerlog")
public class WxTimerLogController extends BaseController
{
    private String prefix = "wechatprogram/wxtimerlog";

    @Autowired
    private IWxTimerLogService wxTimerLogService;

    @RequiresPermissions("wechatprogram:wxtimerlog:view")
    @GetMapping()
    public String wxtimerlog()
    {
        return prefix + "/wxtimerlog";
    }

    /**
     * 查询定时任务执行记录列表
     */
    @RequiresPermissions("wechatprogram:wxtimerlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxTimerLog wxTimerLog)
    {
        startPage();
        List<WxTimerLog> list = wxTimerLogService.selectWxTimerLogList(wxTimerLog);
        return getDataTable(list);
    }

    /**
     * 导出定时任务执行记录列表
     */
    @RequiresPermissions("wechatprogram:wxtimerlog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxTimerLog wxTimerLog)
    {
        List<WxTimerLog> list = wxTimerLogService.selectWxTimerLogList(wxTimerLog);
        ExcelUtil<WxTimerLog> util = new ExcelUtil<WxTimerLog>(WxTimerLog.class);
        return util.exportExcel(list, "wxtimerlog");
    }

    /**
     * 新增定时任务执行记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存定时任务执行记录
     */
    @RequiresPermissions("wechatprogram:wxtimerlog:add")
    @Log(title = "定时任务执行记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxTimerLog wxTimerLog)
    {
        return toAjax(wxTimerLogService.insertWxTimerLog(wxTimerLog));
    }

    /**
     * 修改定时任务执行记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WxTimerLog wxTimerLog = wxTimerLogService.selectWxTimerLogById(id);
        mmap.put("wxTimerLog", wxTimerLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存定时任务执行记录
     */
    @RequiresPermissions("wechatprogram:wxtimerlog:edit")
    @Log(title = "定时任务执行记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxTimerLog wxTimerLog)
    {
        return toAjax(wxTimerLogService.updateWxTimerLog(wxTimerLog));
    }

    /**
     * 删除定时任务执行记录
     */
    @RequiresPermissions("wechatprogram:wxtimerlog:remove")
    @Log(title = "定时任务执行记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxTimerLogService.deleteWxTimerLogByIds(ids));
    }
}
